/*
 * @Date: 2020-11-27 10:20:21
 * @LastEditors: 小枫
 * @description: description
 * @LastEditTime: 2020-11-27 13:07:54
 * @FilePath: \stu-nest\src\modules\email\email\email.controller.ts
 */
import {
  Controller,
  Get,
  HttpException,
  HttpStatus,
  Query,
  UseFilters,
} from '@nestjs/common';
import { ApiQuery, ApiTags } from '@nestjs/swagger';
import { HttpExceptionFilter } from 'src/common/filter/http-exception.filter';
import { EmailService } from './email.service';

@Controller('/email')
@UseFilters(new HttpExceptionFilter())
export class EmailController {
  constructor(private readonly emailService: EmailService) {}

  @Get('send')
  @ApiTags('email')
  @ApiQuery({ name: 'email', required: true })
  send(@Query('email') email: string): string {
    if (!email) {
      throw new HttpException(
        {
          status: HttpStatus.BAD_REQUEST,
          message: '参数必填',
          error: 'email is must',
        },
        HttpStatus.BAD_REQUEST,
      );
    }
    this.emailService.sendEmail(email);
    return 'ok';
  }
}
